package com.wengzw.eduservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wengzw.commonutils.R;
import com.wengzw.eduservice.entity.EduTeacher;
import com.wengzw.eduservice.entity.User;
import com.wengzw.eduservice.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/eduservice/user")
//@CrossOrigin
public class EduLoginController {

    @Autowired
    private LoginService loginService;

    //login
    @PostMapping("login")
    public R login() {
        return R.ok().data("token","admin");
    }
    //info
    @GetMapping("info")
    public R info() {
        return R.ok().data("roles","[admin]").data("name","admin").data("avatar","https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
    }
    @PostMapping("login1/{username}/{password}")
    public R login1(@PathVariable String username,
                    @PathVariable String password) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        if(username != null && password != null){
            wrapper.eq("username",username).eq("password",password);
        }
        List<User> list = loginService.list(wrapper);
        if(!list.isEmpty()){
            return R.ok().data("username",username);
        }
        else {
            return R.error();
        }
    }
}
